package com.zzzy.framework.service.permission;

import com.zzzy.framework.dto.LoginUser;
import com.zzzy.framework.common.util.SecurityUtils;
import org.springframework.stereotype.Service;

/**
 * Description: 权限校验
 *
 * @author fc
 * @date 2024/4/17
 */
@Service("pvs")
public class PermissionValidateService {

    /**
     * 判断是否有权限
     *
     * @param permission 权限
     * @return 是否
     */
    public boolean hasPermission(String permission){
        LoginUser loginUser = SecurityUtils.getLoginUser();
        return loginUser.getPermissions().contains(permission);
    }

    public boolean hasAnyPermission(String... permissions){
        LoginUser loginUser = SecurityUtils.getLoginUser();
        for (String permission : permissions) {
            if (loginUser.getPermissions().contains(permission)) {
                return true;
            }
        }
        return false;
    }
}
